package cn.bfay.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;

/**
 * RedissionConfig.
 *
 * @author wangjiannan
 * @since 2021/9/24
 */
@Configuration
public class RedissionConfig {
    /**
     * redisson客户端.
     *
     * @return {@link RedissonClient}
     * @throws IOException e
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() throws IOException {
        Config config = Config.fromYAML(new ClassPathResource("redisson.yml").getInputStream());
        //Config config = Config.fromYAML(new ClassPathResource("application-single-"+env.getActiveProfiles()[0]+".yml").getInputStream());
        return Redisson.create(config);
    }
}
